package dl.bukkit.myststus.library.container;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

public class MapContainer<E, V> {

    private final Map<E, V> map;
    private Class<?>[] classes = null;

    public MapContainer(Map<E, V> map) {
        this.map = map;
    }

    public MapContainer(Map<E, V> map, Class<?>... classes) {
        this(map);
        this.classes = classes;
    }

    public final void register(E e, Class<? extends V> cls, Object... objects) {
        try {
            Constructor<? extends V> constructor = classes == null ? cls.getDeclaredConstructor() : cls.getDeclaredConstructor(classes);
            constructor.setAccessible(true);
            map.put(e, constructor.newInstance(objects));
        }catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException exception) {
            exception.printStackTrace();
        }
    }

    public Map<E, V> getMap() {
        return map;
    }

    public V get(E e) {
        return map.get(e);
    }
}
